package com.itheima.mall.service.pmsService;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.pojo.pms.PmsProductAttributeCategory;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PmsProductAttributeCategoryService {

    @DubboReference
    private PmsProductAttributeCategoryApi productAttributeCategoryApi;

    public Map page(int pageNum, int pageSize) {
        // 分页构造器
        Page<PmsProductAttributeCategory> pageInfo = new Page<>(pageNum,pageSize);
        //分页条件查询
        Page<PmsProductAttributeCategory> page = productAttributeCategoryApi.page(pageInfo);
        //获取数据集合
        List<PmsProductAttributeCategory> records = page.getRecords();
        //定义Map存储数据
        Map<String,Object> map = new HashMap<>();
        map.put("pageNum",pageNum); // 当前页
        map.put("pageSize",pageSize); // 每页总数
        map.put("total",page.getTotal()); // 总数据
        map.put("totalPage",page.getPages()); // 总页数
        map.put("list",records);
        return map;
    }


    public List<PmsProductAttributeCategory> list() {
        return null;
    }

    public void save(PmsProductAttributeCategory category) {
        productAttributeCategoryApi.save(category);
    }

    public void removeById(Long id) {
        productAttributeCategoryApi.removeById(id);
    }

    public PmsProductAttributeCategory updateById(Long id, String name) {
        return productAttributeCategoryApi.updateByid(id,name);
    }

    public PmsProductAttributeCategory getById(String id) {
        return productAttributeCategoryApi.getById(id);
    }
}
